﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ProjScan.Modules;
using UnityEngine;

namespace ProjScan.Tools
{
	// Token: 0x0200016F RID: 367
	internal class ScanLog
	{
		// Token: 0x06000CEB RID: 3307 RVA: 0x00039878 File Offset: 0x00037A78
		public ScanLog()
		{
			this.dicModuleToLogName = new Dictionary<Module, string>();
			this.dicModuleToLogName.Add(Module.Manager, "MAIN");
			this.dicModuleToLogName.Add(Module.Art_Assets_Check, "ART");
			this.dicModuleToLogName.Add(Module.Art_Assets_Fix, "ART FIX");
			this.dicModuleToLogName.Add(Module.Basic_Assets_Check, "BAS");
			this.dicModuleToLogName.Add(Module.Basic_Assets_Fix, "BAS FIX");
			this.dicModuleToLogName.Add(Module.Global_Settings_Check, "GLO");
			this.dicModuleToLogName.Add(Module.Global_Settings_Fix, "GLO FIX");
			this.dicModuleToLogName.Add(Module.CS_Check, "CSC");
			this.dicModuleToLogName.Add(Module.CS_Fix, "CS FIX");
			this.dicModuleToLogName.Add(Module.Custom_Rules_Check, "CUS");
			this.dicModuleToLogName.Add(Module.Custom_Rules_Fix, "CUS FIX");
			this.dicModuleToLogName.Add(Module.Effects_Play_Check, "EFF");
			this.dicModuleToLogName.Add(Module.Lua_Check, "LUA");
			this.dicModuleToLogName.Add(Module.Lua_Fix, "LUA FIX");
			this.dicModuleToLogName.Add(Module.Scenes_Check, "SCE");
			this.dicModuleToLogName.Add(Module.Scenes_Fix, "SCE FIX");
			this.dicModuleToLogName.Add(Module.Shader_Analysis, "SHA");
			this.dicModuleToLogName.Add(Module.Shader_Fix, "SHA FIX");
			this.dicModuleToLogName.Add(Module.Assets_Reference_Check, "REF");
			this.dicModuleToLogName.Add(Module.Assets_Reference_Fix, "REF FIX");
		}

		// Token: 0x06000CEC RID: 3308 RVA: 0x00039A0C File Offset: 0x00037C0C
		public void OpenScanLog(bool ReceiveUnityLog)
		{
			bool flag = this.streamWriter != null;
			if (flag)
			{
				this.CloseScanLog();
			}
			try
			{
				this.streamWriter = new StreamWriter(ToolsHelper.GetScanOutPut() + "/scan_log.txt", true);
				this.streamWriter.AutoFlush = true;
				if (ReceiveUnityLog)
				{
					Application.logMessageReceived += new Application.LogCallback(this.LoginCallBack);
				}
			}
			catch (Exception ex)
			{
				Debug.LogError(ToolsHelper.GetScanOutPut() + "/scan_log.txt 文件被占用，跳过日志文件输出");
				this.CloseScanLog();
			}
		}

		// Token: 0x06000CED RID: 3309 RVA: 0x00039AA8 File Offset: 0x00037CA8
		public void CloseScanLog()
		{
			bool flag = this.streamWriter != null;
			if (flag)
			{
				this.streamWriter.Close();
				this.streamWriter = null;
			}
			Application.logMessageReceived -= new Application.LogCallback(this.LoginCallBack);
		}

		// Token: 0x06000CEE RID: 3310 RVA: 0x000069D6 File Offset: 0x00004BD6
		public void LogInfo(Module module_0)
		{
			this.LogInfo(string.Format("{{ {0} }} -------------------------------------", module_0.ToString()));
		}

		// Token: 0x06000CEF RID: 3311 RVA: 0x00039AEC File Offset: 0x00037CEC
		public void LogException(Exception exception_0, string string_0, string string_1)
		{
			this.LogInfo(ScanLog.LogLevel.EXCEPTION, Module.Unknown, string_0, string.Concat(new string[]
			{
				string_1,
				(exception_0.GetType() == null) ? null : exception_0.GetType().ToString(),
				"\n",
				exception_0.Message,
				"\n",
				exception_0.StackTrace
			}));
		}

		// Token: 0x06000CF0 RID: 3312 RVA: 0x000069F7 File Offset: 0x00004BF7
		public void LogInfo(string str)
		{
			this.Log(ScanLog.LogLevel.INFO, Module.Unknown, ScanLog.Stage.Unknown, null, str);
		}

		// Token: 0x06000CF1 RID: 3313 RVA: 0x00039B54 File Offset: 0x00037D54
		public void LogInfo(Exception _param1, string _param2, string _param3 = "")
		{
			ScanLog.LogLevel logLevel = ScanLog.LogLevel.EXCEPTION;
			Module module = Module.Unknown;
			string[] array = new string[6];
			array[0] = _param3;
			int num = 1;
			Type type = _param1.GetType();
			array[num] = ((type != null) ? type.ToString() : null);
			array[2] = "\n";
			array[3] = _param1.Message;
			array[4] = "\n";
			array[5] = _param1.StackTrace;
			this.LogInfo(logLevel, module, _param2, string.Concat(array));
		}

		// Token: 0x06000CF2 RID: 3314 RVA: 0x00006A06 File Offset: 0x00004C06
		public void LogInfo(Module module_0, string string_0)
		{
			this.Log(ScanLog.LogLevel.INFO, module_0, ScanLog.Stage.Unknown, null, string_0);
		}

		// Token: 0x06000CF3 RID: 3315 RVA: 0x00006A15 File Offset: 0x00004C15
		public void LogInfo(string string_0, string string_1)
		{
			this.Log(ScanLog.LogLevel.INFO, Module.Unknown, ScanLog.Stage.Unknown, string_0, string_1);
		}

		// Token: 0x06000CF4 RID: 3316 RVA: 0x00006A24 File Offset: 0x00004C24
		public void LogInfo(Module module_0, ScanLog.Stage stage_0, string string_0)
		{
			this.Log(ScanLog.LogLevel.INFO, module_0, stage_0, null, string_0);
		}

		// Token: 0x06000CF5 RID: 3317 RVA: 0x00006A33 File Offset: 0x00004C33
		public void LogInfo(ScanLog.LogLevel logLevel_0, string string_0, string string_1)
		{
			this.Log(logLevel_0, Module.Unknown, ScanLog.Stage.Unknown, string_0, string_1);
		}

		// Token: 0x06000CF6 RID: 3318 RVA: 0x00006A42 File Offset: 0x00004C42
		public void LogInfo(Module module, string string_0, string string_1)
		{
			this.Log(ScanLog.LogLevel.INFO, module, ScanLog.Stage.Unknown, string_0, string_1);
		}

		// Token: 0x06000CF7 RID: 3319 RVA: 0x00006A51 File Offset: 0x00004C51
		public void LogInfo(Module module, ScanLog.Stage stage, string string_0, string string_1)
		{
			this.Log(ScanLog.LogLevel.INFO, module, stage, string_0, string_1);
		}

		// Token: 0x06000CF8 RID: 3320 RVA: 0x00006A61 File Offset: 0x00004C61
		public void LogInfo(ScanLog.LogLevel logLevel, Module module, string string_0, string string_1)
		{
			this.Log(logLevel, module, ScanLog.Stage.Unknown, string_0, string_1);
		}

		// Token: 0x06000CF9 RID: 3321 RVA: 0x00006A71 File Offset: 0x00004C71
		public void LogInfo(ScanLog.LogLevel logLevel, Module module, ScanLog.Stage stage, string string_0, string string_1)
		{
			this.Log(logLevel, module, stage, string_0, string_1);
		}

		// Token: 0x06000CFA RID: 3322 RVA: 0x00039BB4 File Offset: 0x00037DB4
		private void Log(ScanLog.LogLevel logLevel, Module module, ScanLog.Stage stage, string string0, string string1)
		{
			bool flag = logLevel == ScanLog.LogLevel.EXCEPTION;
			if (flag)
			{
				ScanLog.UnityLogError(string.Concat(new string[]
				{
					module.ToString(),
					" ",
					stage.ToString(),
					" ",
					string0,
					" ",
					string1
				}));
			}
			StringBuilder stringBuilder = new StringBuilder(ScanLog.NowTime() + " : ");
			bool flag2 = logLevel == ScanLog.LogLevel.EXCEPTION;
			if (flag2)
			{
				stringBuilder.Append("[[-EXCEPTION-]]");
			}
			bool flag3 = module > Module.Unknown;
			if (flag3)
			{
				stringBuilder.Append(" {").Append(this.dicModuleToLogName[module]).Append("}");
			}
			bool flag4 = stage > ScanLog.Stage.Unknown;
			if (flag4)
			{
				stringBuilder.Append(" [").Append(stage.ToString()).Append("]");
			}
			bool flag5 = !string.IsNullOrEmpty(string0);
			if (flag5)
			{
				stringBuilder.Append(" (").Append(string0).Append(") ");
			}
			stringBuilder.Append(string1);
			string text = stringBuilder.ToString();
			bool flag6 = this.streamWriter != null;
			if (flag6)
			{
				this.streamWriter.WriteLine(text);
			}
			else
			{
				ScanLog.WriteOnce(text);
			}
		}

		// Token: 0x06000CFB RID: 3323 RVA: 0x00039D1C File Offset: 0x00037F1C
		private void LogMessage(string string_0)
		{
			bool flag = this.streamWriter != null;
			if (flag)
			{
				this.streamWriter.WriteLine(string_0);
			}
			else
			{
				ScanLog.WriteOnce(string_0);
			}
		}

		// Token: 0x06000CFC RID: 3324 RVA: 0x00039D54 File Offset: 0x00037F54
		public void LogScanInfo(Module module_0, ScanLog.Stage stage_0, string string_0, string string_1)
		{
			bool flag = Singleton<ScanInfo>.Instance.platform != ScanInfo.Platform.Windows;
			if (flag)
			{
				this.Log(ScanLog.LogLevel.INFO, module_0, stage_0, string_0, string_1);
			}
		}

		// Token: 0x06000CFD RID: 3325 RVA: 0x00039D88 File Offset: 0x00037F88
		public void LogScanInfo(string string_0)
		{
			bool flag = Singleton<ScanInfo>.Instance.platform != ScanInfo.Platform.Windows;
			if (flag)
			{
				this.LogMessage(string_0);
			}
		}

		// Token: 0x06000CFE RID: 3326 RVA: 0x00039DB4 File Offset: 0x00037FB4
		public static void WriteOnce(string string_0)
		{
			using (StreamWriter streamWriter = new StreamWriter(ToolsHelper.GetScanOutPut() + "/scan_log.txt", true))
			{
				streamWriter.WriteLine(ScanLog.NowTime() + " : [Static Log] : " + string_0);
			}
		}

		// Token: 0x06000CFF RID: 3327 RVA: 0x00039E10 File Offset: 0x00038010
		private static string NowTime()
		{
			string text = DateTime.Now.ToString("HH:mm:ss");
			return text ?? "";
		}

		// Token: 0x06000D00 RID: 3328 RVA: 0x00006A82 File Offset: 0x00004C82
		public static void UnityLogError(string str)
		{
			Debug.LogError(ScanLog.NowTime() + " : [ProjScan][Error] " + str);
		}

		// Token: 0x06000D01 RID: 3329 RVA: 0x00006A9B File Offset: 0x00004C9B
		public static void UnityLog(string string_0)
		{
			Debug.Log(ScanLog.NowTime() + " : [ProjScan] " + string_0);
		}

		// Token: 0x06000D02 RID: 3330 RVA: 0x00039E40 File Offset: 0x00038040
		private void LoginCallBack(string string_0, string string_1, LogType logType_0)
		{
			bool flag = this.streamWriter != null;
			if (flag)
			{
				this.streamWriter.Write(DateTime.Now.ToString("yyyyMMdd HHmmss") + " : [" + logType_0.ToString() + "]");
				this.streamWriter.WriteLine(string_0);
				this.streamWriter.WriteLine(string_1);
			}
		}

		// Token: 0x040007F3 RID: 2035
		public static ScanLog Instance = new ScanLog();

		// Token: 0x040007F4 RID: 2036
		private StreamWriter streamWriter;

		// Token: 0x040007F5 RID: 2037
		private Dictionary<Module, string> dicModuleToLogName;

		// Token: 0x02000170 RID: 368
		public enum LogLevel
		{
			// Token: 0x040007F7 RID: 2039
			INFO,
			// Token: 0x040007F8 RID: 2040
			EXCEPTION
		}

		// Token: 0x02000171 RID: 369
		public enum Stage
		{
			// Token: 0x040007FA RID: 2042
			Unknown,
			// Token: 0x040007FB RID: 2043
			s1,
			// Token: 0x040007FC RID: 2044
			s2,
			// Token: 0x040007FD RID: 2045
			s3,
			// Token: 0x040007FE RID: 2046
			s4,
			// Token: 0x040007FF RID: 2047
			s5,
			// Token: 0x04000800 RID: 2048
			s6
		}
	}
}
